home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / SASC_6.0_Disk_7.adf / Source_And_Examples / extras / Memlib / mempriv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-30  |  5.1 KB  |  133 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  2. * |_o_o|\\ Copyright (c) 1989, 1990, 1991 The Software Distillery.        *
  3. * |. o.| ||          All Rights Reserved                                  *
  4. * | .  | ||          Written by Doug Walker                               *
  5. * | o  | ||          The Software Distillery                              *
  6. * |  . |//           405 B3 Gooseneck Drive                               *
  7. * ======             Cary, NC 27513                                       *
  8. *                                                                         *
  9. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  10.  
  11.  
  12.  
  13.  
  14.  
  15. /**************************************************************************/
  16. /**************************************************************************/
  17. /**************************************************************************/
  18. /*                                                                        */
  19. /* DO NOT INCLUDE THIS FILE IN YOUR PROGRAM.  IT IS FOR MEMLIB'S INTERNAL */
  20. /* USE ONLY.  USE THE FILE "memwatch.h" FOR YOUR PROGRAM FILES.           */
  21. /*                                                                        */
  22. /**************************************************************************/
  23. /**************************************************************************/
  24. /**************************************************************************/
  25.  
  26.  
  27.  
  28.  
  29. #include <exec/types.h>
  30. #include <exec/memory.h>
  31. #include <exec/ports.h>
  32. #include <proto/exec.h>
  33. #include <proto/dos.h>
  34. #include <string.h>
  35. #include <stdarg.h>
  36.  
  37. #define MWDEBUG 1   /* MWDEBUG is always defined for the library itself */
  38. #include "memwatch.h"
  39.  
  40.  
  41. #ifdef AllocMem
  42. #undef AllocMem
  43. #endif
  44.  
  45. #ifdef FreeMem
  46. #undef FreeMem
  47. #endif
  48.  
  49. #define MWT_CHIP 0
  50. #define MWT_FAST 1
  51.  
  52. #define MW_HEADLEN  4  /* Number of bytes for header sentinel */
  53.  
  54. /* The following string must be >= MW_HEADLEN bytes */
  55. #define MWHEADSTR "HEAD"
  56.                  /*0123*/
  57.  
  58. #define MW_TRAILLEN 16  /* Number of bytes for trailer sentinel */
  59.  
  60. /* The following string must be >= MW_TRAILLEN bytes */
  61. #define MWTRAILSTR "TRAILERTRAILERTR"
  62.                   /*0123456789012345*/
  63.  
  64. struct MWGlobal
  65. {
  66.    LONG flags;          /* Various MWF_ flags, see memwatch.h           */
  67.    LONG num[2];         /* Current number of allocations, chip and fast */
  68.    LONG sum[2];         /* Current amount allocated, chip and fast      */
  69.    LONG max[2];         /* Max amount allocated, chip and fast          */
  70.    LONG lim[2];         /* Limit on allocations, chip and fast          */
  71.    BPTR dbfh;           /* File to send debug output to                 */
  72.    struct MWAlc *first; /* List of active memory allocations            */
  73.    struct MWAlc *freed; /* List of free memory extents                  */
  74.    struct MWAlc *lfree; /* Last allocation freed with free()            */
  75.    struct Task *task;   /* Pointer to owning task's Task structure      */
  76.    char *dbnm;          /* name of debug log file                       */
  77.    int headlen,         /* Length of header sentinel                    */
  78.        traillen;        /* Length of trailer sentinel                   */
  79. };
  80.  
  81. struct MWAlc
  82. {
  83.    struct MWAlc *next;  /* Next memory block in chain           */
  84.    LONG size;           /* Size of allocation in bytes          */
  85.    LONG flags;          /* MEMF_ Flags memory was allocated with*/
  86.    LONG myflags;        /* my flags, see defines below          */
  87.    char *file;          /* Filename containing allocation point */
  88.    LONG line;           /* Line number of allocation            */
  89.    char *ffile;         /* Filename of free point               */
  90.    char *fline;         /* Line number of free point            */
  91.    char header[MW_HEADLEN];     /* Header sentinal               */
  92.    char memory[MW_TRAILLEN+3];  /* Actual allocation comes here  */
  93.                         /* extra bytes cover trailer sentinal*/
  94. };
  95.  
  96. /* Defines for use with MWAlc.myflags */
  97. /* if myflags&MWF_REPMASK == MWF_REPORTED,   */
  98. /* This alloc already reported as trashed    */
  99. /* Use multiple bits in case the 'myflags'   */
  100. /* are trashed, odds are better of detecting */
  101. /* If we ever need more myflag bits, just    */
  102. /* define MWF_REPMASK not to include them    */
  103.  
  104. #define MWF_REPORTED 0xaa55aa50
  105. #define MWF_REPMASK  0xfffffff0
  106.  
  107. #define MWF_ISMALLOC 0x00000001
  108.  
  109. #define MWATRASH     0xaa  /* Trash allocated memory with this           */
  110. #define MWFTRASH     0x55  /* Trash freed memory with this               */
  111.  
  112. void MWHold   (void);
  113. void MWPurge  (void);
  114. void MWPanic  (char *);
  115. void MWPrintf (char *, ...);
  116. int MWCheckA  (struct MWAlc *);
  117.  
  118. /* If you want debugging to use the serial port, you must have */
  119. /* Commodore's debug.lib.  If you do, change the #define below */
  120. /* to a 1 and add debug.lib to your link line.                 */
  121. #define USEDEBUGLIB 0
  122. #if USEDEBUGLIB
  123. /* Defined in Commodore's debug.lib */
  124. void __stdargs KPutStr(char *string);
  125. #else
  126. #define KPutStr(x)
  127. #endif
  128.  
  129. #define MWPrintAlc(mwa) \
  130.    MWPrintf("0x%08lx length %ld allocated line %ld file \"%s\"\n", \
  131.             (mwa)->memory, (mwa)->size, (mwa)->line, (mwa)->file);
  132.  
  133.